#include <vector>
#include <iostream>

using namespace std;

class Solution 
{
public:
	void setZeroes(vector<vector<int> > &matrix) 
	{
		// Start typing your C/C++ solution below
		// DO NOT write int main() function
		size_t m = matrix.size();
		if(m<=0)
			return;

		size_t n = matrix[0].size();
		if(n<=0)
			return;

		bool lastZ = false;
		for(size_t i=0;i<n;i++)
		{
			if(matrix[0][i] == 0)
			{
				lastZ = true;
				break;
			}
		}

		if(lastZ)
		{
			for(size_t i=0;i<n;i++)
			{
				if(matrix[0][i]==0)
					matrix[0][i] = -1;
				else
					matrix[0][i] = 0;
			}
		}

		for(size_t i=1;i<m;i++)
		{
			bool curZ = false;
			for(size_t j=0;j<n;j++)
			{
				if(matrix[i][j]==0)
				{
					curZ = true;
					break;
				}
			}

			if(curZ)
			{
				if(lastZ)
				{
					for(size_t j=0;j<n;j++)
					{
						if(matrix[i-1][j]==-1 || matrix[i][j]==0)
						{
							matrix[i-1][j] = 0;
							matrix[i][j] = -1;
						}
						else
							matrix[i][j] = 0;
					}
				}
				else
				{
					for(size_t j=0;j<n;j++)
					{
						if(matrix[i-1][j]==0 || matrix[i][j] == 0)
							matrix[i][j] = -1;
						else
							matrix[i][j] = 0;
					}
				}
			}
			else
			{
				for(size_t j=0;j<n;j++)
				{
					if(lastZ && matrix[i-1][j]==-1)
					{
						matrix[i-1][j] = 0;
						matrix[i][j] = 0;
					}
					else if(!lastZ && matrix[i-1][j]==0)
						matrix[i][j]=0;
				}
			}

			lastZ = curZ;
		}


		for(size_t i=0;i<n;i++)
		{
			if((lastZ && matrix[m-1][i]==-1) || 
				(!lastZ && matrix[m-1][i] == 0))
			{
				for(size_t j=0;j<m;j++)
					matrix[j][i] = 0;
			}
		}


	}
};


int main()
{
	int m,n;
	Solution s;
	while(cin>>m)
	{
		if(m==0)
			break;
		cin>>n;
		vector<vector<int> > matrix(m);
		for(int i=0;i<m;i++)
		{
			matrix[i] = vector<int>(n);
			for(int j=0;j<n;j++)
				cin>>matrix[i][j];
		}

		s.setZeroes(matrix);
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
				cout<<matrix[i][j]<<" ";
			cout<<endl;
		}
	}
}